<template>
  <div class="article-setlike">
    <van-icon
      :color="attitude?'#777':'#e22829'"
      :name="attitude?'good-job-o':'good-job'"
      @click="onLiked"
    />
  </div>
</template>

<script>
import { setDislike, setLike } from '@/api/article.js'
export default {
  props: {
    articleId: {
      type: [Number, Object],
      required: true
    },
    attitude: {
      type: Boolean(),
      required: true
    }
  },
  data () {
    return {
      // is_art_like: false
    }
  },
  methods: {
    async onLiked () {
      // -1  1 ---true 未选中    0 -->false 选中
      // loading加载提示
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        message: '加载中...',
        forbidClick: true
      })
      try {
        if (this.attitude) {
          // 已经收藏 进行取消收藏操作
          await setDislike(this.articleId)
        } else {
          // 进行收藏操作
          await setLike(this.articleId)
        }
        this.$toast('操作成功')
        // this.is_art_like = !this.is_art_like
        this.$emit('input', !this.attitude)
      } catch (err) {
        this.$toast('操作失败')
      }
    }
  },
  computed: {
    // changeNumber: {}
  },
  watch: {},
  filters: {},
  components: {},
  created () { },
  model: {
    prop: 'attitude'
  },
  mounted () { }
}
</script>

<style scoped lang='less'>
</style>
